home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / flxkey.exe / READKEY3.PAS < prev   
Pascal/Delphi Source File  |  1993-02-21  |  6KB  |  145 lines

  1.  
  2. (**********************************************************************)
  3. (* Simple program to demonstrate how to use the FlxKey unit to obtain *)
  4. (* user-data from an encrypted "password" registration-key file,      *)
  5. (* using one "embedded" encryption-code string and one user-entered   *)
  6. (* "password" encryption-code string.                                 *)
  7. (*                                                                    *)
  8. (* NOTE: Before you can compile this program, you must first          *)
  9. (*       compile and run the "RANDCODE.PAS" program to generate       *)
  10. (*       the two "random" encryption-code binary data files. Then     *)
  11. (*       run the "batch" file called "DAT2OBJ.BAT" to convert         *)
  12. (*       these two binary data files to "object" format files.        *)
  13. (**********************************************************************)
  14.  
  15. program Read_FlxKey_Demo3;
  16. uses
  17.   Crt,
  18.   FlxKey;
  19.  
  20. type
  21.               (* 20 character string-pointer definition.              *)
  22.   post_20 = ^st_20;
  23.  
  24. var           (* Variable set by ReadFlxKey routine, that indicates   *)
  25.               (* the difference in days between the current date and  *)
  26.               (* the date encrypted into the registration-key file.   *)
  27.   DaysOld,
  28.  
  29.               (* This variable is used to check for errors returned   *)
  30.               (* by ReadFlxKey routine.                               *)
  31.   ErrorCode   : word;
  32.  
  33.               (* Encryption-code string-pointer, used to decrypt the  *)
  34.               (* data in the encrypted registration-key file.         *)
  35.   Ecode1Ptr   : post_20;
  36.  
  37.               (* User "password" encryption-code string.              *)
  38.   st_Password : st_20;
  39.  
  40.               (* This is the full path/filename of the encrypted      *)
  41.               (* registration-key file to be decrypted.               *)
  42.   RegKeyName  : st_79;
  43.  
  44.               (* Record variable to hold the data decrypted from the  *)
  45.               (* encrypted registration-key file.                     *)
  46.   TempKeyRec  : rc_Flx;
  47.  
  48.   {$F+}       (* Declare the following two procedures as "FAR".       *)
  49.  
  50.               (* "Fake" procedure that contains first encryption-code *)
  51.               (* string.                                              *)
  52.   procedure Ecode1Data; external;
  53.   {$L ECODE1.OBJ}
  54.  
  55.   {$F-}       (* Turn off "FAR" declaration.                          *)
  56.  
  57.               (* Main program execution block.                        *)
  58. BEGIN
  59.               (* Initialize the encryption-code string pointer to     *)
  60.               (* it's data.                                           *)
  61.   Ecode1ptr := addr(Ecode1Data);
  62.  
  63.               (* Clear the temporary key-record variable.             *)
  64.   fillchar(TempKeyRec, sizeof(TempKeyRec), 0);
  65.  
  66.               (* Full path/filename for the encrypted registration-   *)
  67.               (* key file to be decrypted.                            *)
  68.   RegKeyName := 'DEMO3.KEY';
  69.  
  70.               (* Enter User "password" encryption-code string.        *)
  71.   writeln;
  72.   write('Enter Password : ');
  73.   readln(st_Password);
  74.  
  75.               (* Decrypt the registration-key file, and retreive it's *)
  76.               (* data.                                                *)
  77.               (* NOTE: A 10 second delay and message are present in   *)
  78.               (*       the un-registered copy of the FlxKey unit.     *)
  79.   ReadFlxKey(Ecode1Ptr^, st_Password, RegKeyName, TempKeyRec, DaysOld,
  80.              ErrorCode);
  81.  
  82.               (* Clear the screen.                                    *)
  83.   clrscr;
  84.   writeln;
  85.  
  86.               (* Check for errors.                                    *)
  87.   if (ErrorCode <> 0) then
  88.     case (ErrorCode AND $FF) of
  89.        1 : writeln(' Error! One or more encryption-codes is blank.');
  90.        2 : writeln(' Error! Filename for registration-key file is blank.');
  91.        3 : writeln(' HEAP allocation error. Unable to allocate 1024 ' +
  92.                    'buffer.');
  93.        4 : writeln(' BlocWrite error.');
  94.        5 : writeln(' BlockRead error.');
  95.        6 : writeln(' Date error. PC''s system date pre-dates ' +
  96.                    'registration-key date.');
  97.        7 : writeln(' Password is NOT correct.');
  98.  
  99.               (* I/O error!                                           *)
  100.       16 : begin
  101.              writeln(' I/O error = ', (ErrorCode shr 8));
  102.  
  103.               (* Standard Turbo Pascal error-codes. See TP manuals,   *)
  104.               (* as there are many types of errors to check for.      *)
  105.              case (ErrorCode shr 8) of
  106.                  2 : writeln(' File not found.');
  107.                  3 : writeln(' Path not found.');
  108.                  4 : writeln(' Too many files open.');
  109.                  5 : writeln(' File access denied.');
  110.                100 : writeln(' Disk read error.');
  111.                103 : writeln(' File not open')
  112.              end  (* case (ErrorCode shr 8) of                        *)
  113.            end
  114.     end       (* case (ErrorCode AND $FF) of                          *)
  115.   else
  116.               (* Else NO errors occurred.                             *)
  117.     begin
  118.               (* Display the decrypted registration-key data.         *)
  119.       writeln('Key is ', DaysOld, ' days old');
  120.       writeln;
  121.       with TempKeyRec do
  122.         begin
  123.           writeln(' FirstName    = ', FirstName);
  124.           writeln(' LastName     = ', LastName);
  125.           writeln(' Address1     = ', Address1);
  126.           writeln(' Address2     = ', Address2);
  127.           writeln(' Address3     = ', Address3);
  128.           writeln(' AppName      = ', AppName);
  129.           writeln(' Version      = ', Version);
  130.           writeln(' Serial Num   = ', Serial);
  131.  
  132.               (* Standard TP "UnPackTime" and "PackTime" routines     *)
  133.               (* can be used to manipulate "packed date" data.        *)
  134.           writeln(' Packed Date  = ', Date);
  135.  
  136.           writeln(' Access Level = ', Access);
  137.  
  138.           writeln(' MiscData     = ', MiscData)
  139.  
  140.         end
  141.     end
  142. END.
  143.  
  144.  
  145.